﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;

using Eneta.Portal.Common.Repository;

using Microsoft.SharePoint;

namespace Eneta.Portal.Admin.Controls
{
    public class AdminAnnouncementListControl : UserControl
    {
        protected Repeater _announcementsRepeater;
        protected Label _noAnnouncementsLabel;

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var repository = new AnnouncementRepository(SPContext.Current.Web);
            var results = repository.GetPendingAnnouncements();

            _announcementsRepeater.Visible = false;
            _noAnnouncementsLabel.Visible = false;

            if(results.Count > 0)
            {
                _announcementsRepeater.DataSource = results;
                _announcementsRepeater.DataBind();
                _announcementsRepeater.Visible = true;
            }
            else
            {
                _noAnnouncementsLabel.Visible = true;
            }
        }
    }
}
